from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-08-14 14:11:56.157630
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 14, Aug, 2021
Time: 14:12:01
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.6247
Nobs: 383.000 HQIC: -46.1845
Log likelihood: 4113.72 FPE: 6.06121e-21
AIC: -46.5525 Det(Omega_mle): 4.80635e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.446855 0.096389 4.636 0.000
L1.Burgenland 0.110846 0.049757 2.228 0.026
L1.Kärnten -0.116642 0.024440 -4.773 0.000
L1.Niederösterreich 0.166703 0.106690 1.563 0.118
L1.Oberösterreich 0.117109 0.105451 1.111 0.267
L1.Salzburg 0.291900 0.051779 5.637 0.000
L1.Steiermark 0.013825 0.068707 0.201 0.841
L1.Tirol 0.123417 0.054197 2.277 0.023
L1.Vorarlberg -0.114255 0.048848 -2.339 0.019
L1.Wien -0.033635 0.094692 -0.355 0.722
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.002983 0.227656 0.013 0.990
L1.Burgenland -0.049636 0.117518 -0.422 0.673
L1.Kärnten 0.035260 0.057724 0.611 0.541
L1.Niederösterreich -0.251441 0.251985 -0.998 0.318
L1.Oberösterreich 0.550990 0.249058 2.212 0.027
L1.Salzburg 0.314961 0.122295 2.575 0.010
L1.Steiermark 0.112393 0.162275 0.693 0.489
L1.Tirol 0.301780 0.128004 2.358 0.018
L1.Vorarlberg -0.013031 0.115371 -0.113 0.910
L1.Wien 0.008247 0.223648 0.037 0.971
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.253479 0.049316 5.140 0.000
L1.Burgenland 0.096352 0.025457 3.785 0.000
L1.Kärnten -0.003283 0.012504 -0.263 0.793
L1.Niederösterreich 0.233619 0.054586 4.280 0.000
L1.Oberösterreich 0.154795 0.053952 2.869 0.004
L1.Salzburg 0.037176 0.026492 1.403 0.161
L1.Steiermark 0.009873 0.035153 0.281 0.779
L1.Tirol 0.073545 0.027729 2.652 0.008
L1.Vorarlberg 0.057425 0.024992 2.298 0.022
L1.Wien 0.087879 0.048448 1.814 0.070
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191724 0.048183 3.979 0.000
L1.Burgenland 0.043104 0.024873 1.733 0.083
L1.Kärnten -0.006729 0.012217 -0.551 0.582
L1.Niederösterreich 0.123944 0.053332 2.324 0.020
L1.Oberösterreich 0.312913 0.052713 5.936 0.000
L1.Salzburg 0.101901 0.025884 3.937 0.000
L1.Steiermark 0.138650 0.034345 4.037 0.000
L1.Tirol 0.076332 0.027092 2.818 0.005
L1.Vorarlberg 0.055341 0.024418 2.266 0.023
L1.Wien -0.038123 0.047335 -0.805 0.421
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.201986 0.096179 2.100 0.036
L1.Burgenland -0.060527 0.049649 -1.219 0.223
L1.Kärnten -0.036844 0.024387 -1.511 0.131
L1.Niederösterreich 0.083910 0.106457 0.788 0.431
L1.Oberösterreich 0.197060 0.105221 1.873 0.061
L1.Salzburg 0.264133 0.051667 5.112 0.000
L1.Steiermark 0.076340 0.068557 1.114 0.265
L1.Tirol 0.123720 0.054079 2.288 0.022
L1.Vorarlberg 0.116352 0.048742 2.387 0.017
L1.Wien 0.038156 0.094486 0.404 0.686
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.032059 0.075254 0.426 0.670
L1.Burgenland 0.027074 0.038847 0.697 0.486
L1.Kärnten 0.050413 0.019081 2.642 0.008
L1.Niederösterreich 0.197725 0.083296 2.374 0.018
L1.Oberösterreich 0.345438 0.082328 4.196 0.000
L1.Salzburg 0.048043 0.040426 1.188 0.235
L1.Steiermark -0.003241 0.053641 -0.060 0.952
L1.Tirol 0.116173 0.042313 2.746 0.006
L1.Vorarlberg 0.062124 0.038137 1.629 0.103
L1.Wien 0.125476 0.073929 1.697 0.090
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.176281 0.091785 1.921 0.055
L1.Burgenland 0.021640 0.047380 0.457 0.648
L1.Kärnten -0.057652 0.023273 -2.477 0.013
L1.Niederösterreich -0.114328 0.101593 -1.125 0.260
L1.Oberösterreich 0.188734 0.100413 1.880 0.060
L1.Salzburg 0.032033 0.049306 0.650 0.516
L1.Steiermark 0.304022 0.065425 4.647 0.000
L1.Tirol 0.492028 0.051608 9.534 0.000
L1.Vorarlberg 0.065992 0.046514 1.419 0.156
L1.Wien -0.105549 0.090168 -1.171 0.242
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.155153 0.099852 1.554 0.120
L1.Burgenland -0.002626 0.051545 -0.051 0.959
L1.Kärnten 0.062342 0.025318 2.462 0.014
L1.Niederösterreich 0.193889 0.110523 1.754 0.079
L1.Oberösterreich -0.122556 0.109240 -1.122 0.262
L1.Salzburg 0.244219 0.053640 4.553 0.000
L1.Steiermark 0.156786 0.071176 2.203 0.028
L1.Tirol 0.050389 0.056144 0.897 0.369
L1.Vorarlberg 0.122417 0.050603 2.419 0.016
L1.Wien 0.143302 0.098094 1.461 0.144
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.499745 0.054198 9.221 0.000
L1.Burgenland -0.016718 0.027977 -0.598 0.550
L1.Kärnten -0.009352 0.013742 -0.681 0.496
L1.Niederösterreich 0.195909 0.059990 3.266 0.001
L1.Oberösterreich 0.262440 0.059293 4.426 0.000
L1.Salzburg 0.021852 0.029115 0.751 0.453
L1.Steiermark -0.027327 0.038633 -0.707 0.479
L1.Tirol 0.069675 0.030474 2.286 0.022
L1.Vorarlberg 0.058163 0.027466 2.118 0.034
L1.Wien -0.052186 0.053244 -0.980 0.327
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.018638 0.065903 0.137289 0.125626 0.035970 0.066915 -0.002149 0.184321
Kärnten 0.018638 1.000000 -0.055602 0.128913 0.045551 0.069032 0.458664 -0.093603 0.098117
Niederösterreich 0.065903 -0.055602 1.000000 0.290340 0.090461 0.273671 0.013034 0.147258 0.255956
Oberösterreich 0.137289 0.128913 0.290340 1.000000 0.174725 0.294567 0.164237 0.119584 0.136164
Salzburg 0.125626 0.045551 0.090461 0.174725 1.000000 0.129065 0.049776 0.107426 0.052880
Steiermark 0.035970 0.069032 0.273671 0.294567 0.129065 1.000000 0.126946 0.087395 -0.024451
Tirol 0.066915 0.458664 0.013034 0.164237 0.049776 0.126946 1.000000 0.035648 0.123059
Vorarlberg -0.002149 -0.093603 0.147258 0.119584 0.107426 0.087395 0.035648 1.000000 -0.045962
Wien 0.184321 0.098117 0.255956 0.136164 0.052880 -0.024451 0.123059 -0.045962 1.000000